package Models;

import java.util.ArrayList;

/**
 * @author Erik
 */
public class KitchenCatalogue
{
    private ArrayList<Kitchen> kitchens;
    private static KitchenCatalogue instance = new KitchenCatalogue();

    private KitchenCatalogue()
    {
		ItemCollection items = ItemCollection.getInstance();
        this.kitchens = new ArrayList<Kitchen>();
		ArrayList<Item> cupboards = new ArrayList<Item>(); cupboards.add(items.getItem(106));
		ArrayList<Item> drawers = new ArrayList<Item>(); drawers.add(items.getItem(105));
		ArrayList<Item> appliances = new ArrayList<Item>(); appliances.add(items.getItem(101));
		this.kitchens.add(new Kitchen("Fiskekøkn", 10000d, items.getItem(100), cupboards, drawers, appliances));
    }

    public static KitchenCatalogue getInstance()
	{
		return KitchenCatalogue.instance;
	}

    public boolean addKitchen(Kitchen newKitchen)
    {
        return this.kitchens.add(newKitchen);
    }

    public ArrayList<Kitchen> findKitchen(String name,double price, Item tableTop, ArrayList<Item> cupboards, ArrayList<Item> drawers, ArrayList<Item> appliances, Item otherItem)
    {
        boolean found = false;
        ArrayList<Kitchen> result = new ArrayList<Kitchen>();

        for (Kitchen kitchen : this.kitchens)
		{
			if(kitchen.isActivated())
			{
				if (name != null)
				{
					if (kitchen.getName().toLowerCase().contains(name.toLowerCase()))
					{ found = true; }
				}
				else if (kitchen.getPrice() == price)
				{ found = true; }
				else if (kitchen.getTableTop() == tableTop)
				{ found = true; }
				else if (kitchen.getCupboards() == cupboards)
				{ found = true; }
				else if (kitchen.getDrawers() == drawers)
				{ found = true; }
				else if (kitchen.getAppliances() == appliances)
				{ found = true; }
				else if (kitchen.getTableTop().equals(otherItem))
				{ found = true; }
				else if (kitchen.getCupboards().contains(otherItem))
				{ found = true; }
				else if (kitchen.getDrawers().contains(otherItem))
				{ found = true; }
				else if (kitchen.getAppliances().contains(otherItem))
				{ found = true; }

				if (found)
				{
					result.add(kitchen);
				}
			}
        }
		return result;
    }

    public Kitchen getKitchen(int id)
    {
        for(Kitchen kitchen : this.kitchens){
            if(kitchen.getId() == id){
                return kitchen;
            }
        }
        return null;
    }

    public ArrayList<Kitchen> getAllKitchens()
	{
		ArrayList<Kitchen> activatedKitchens = new ArrayList<Kitchen>();
		for (Kitchen kitchen : this.kitchens)
		{
			if(kitchen.isActivated())
			{
				activatedKitchens.add(kitchen);
			}
		}
		return activatedKitchens;
	}

    public void removeKitchen(Kitchen kitchen)
    {
        kitchen.setActivated(false);
    }
}
